package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.BigClient;
import cn.wolfcode.crm.query.BigClientQueryObject;
import cn.wolfcode.crm.service.IBigClientService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("bigClient")
public class BigClientController {

    @Autowired
    private IBigClientService bigClientService;

    @RequestMapping("index")
    public String index(){
        return "bigClient/list";
    }

    @ResponseBody
    @RequestMapping("list")
    public PageResult index(BigClientQueryObject qo){
        PageResult result = bigClientService.queryListByQo(qo);
        return result;
    }

    @ResponseBody
    @RequestMapping("save")
    public JsonResult save(BigClient bigClient){
        JsonResult result = new JsonResult();
        try {
            bigClientService.insert(bigClient);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("保存出错!");
        }
        return result;
    }

    @ResponseBody
    @RequestMapping("update")
    public JsonResult update(BigClient bigClient){
        JsonResult result = new JsonResult();
        try {
            bigClientService.updateByPrimaryKey(bigClient);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("编辑出错!");
        }
        return result;
    }

    @ResponseBody
    @RequestMapping("delete")
    public JsonResult delete(Long id){
        JsonResult result = new JsonResult();
        try {
            if (id!=null){
                bigClientService.deleteByPrimaryKey(id);
            }
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("编辑出错!");
        }
        return result;
    }

    @ResponseBody
    @RequestMapping("queryBigClientByid")
    public BigClient queryBigClientByid(Long id){
        return bigClientService.selectByPrimaryKey(id);
    }

    @ResponseBody
    @RequestMapping("queryAllBigClient")
    public List<BigClient> queryAllBigClient(){
        return bigClientService.selectAll();
    }

    @ResponseBody
    @RequestMapping("contract")
    public JsonResult contract(Long id){
        JsonResult result = new JsonResult();
        try {
            bigClientService.contract(id);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("编辑出错!");
        }
        return result;
    }
}
